<template >
  <div class="ordermanage-container">
    <breadcrumb style="position: absolute;width:100%;"></breadcrumb>
    <div class="content">
      <div class="query">
        <div class="margin_right_20">
          订单编号:&nbsp;
          <el-input
            v-model="orderNo"
            placeholder="请输入订单编号"
            style="width:200px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          用户ID:&nbsp;
          <el-input
            v-model="userId"
            placeholder="请输入用户ID"
            style="width:100px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          商品名称:&nbsp;
          <el-input
            v-model="goodsName"
            placeholder="请输入商品名称"
            style="width:180px;height:30px;"
            @keyup.enter.native="get_orderList(1)"
          ></el-input>
        </div>
        <div class="margin_right_20">
          订单所属活动:&nbsp;
          <el-select v-model="positionId" style="width: 130px;">
            <el-option
              v-for="item in options1"
              :key="item.id"
              :label="item.position"
              :value="item.id"
            ></el-option>
          </el-select>
        </div>

        <div class="btn">
          <el-button type="primary" icon="el-icon-search" @click="get_orderList(1)">查询</el-button>
        </div>
      </div>

      <div class="query">
        <div class="start_time margin_right_20">
          创建时间(开始):&nbsp;
          <div class="block">
            <el-date-picker
              type="datetime"
              v-model="beginTime"
              placeholder="选择日期时间"
              style="width:200px"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
        <div class="end_time margin_right_20">
          创建时间(结束):&nbsp;
          <div class="block">
            <el-date-picker
              type="datetime"
              placeholder="选择日期时间"
              style="width:200px"
              v-model="endTime"
              default-time="23:59:59"
              value-format="yyyy-MM-dd HH:mm:ss"
            ></el-date-picker>
          </div>
        </div>
      </div>
      <div class="table">
        <el-table :data="orderList" style="width: 100%" height="548">
          <el-table-column prop="orderNo" label="订单编号" width="200px"></el-table-column>
          <el-table-column prop="userId" label="用户ID"></el-table-column>
          <el-table-column prop="position" label="订单所属活动"></el-table-column>
          <el-table-column prop="ofCash" label="订单金额"></el-table-column>
          <el-table-column prop="phone" label="接收卡密手机号"></el-table-column>
          <el-table-column prop="status" label="订单状态"></el-table-column>
          <el-table-column prop="ofOrderNo" label="卡密流水号"></el-table-column>
          <el-table-column prop="createTime" label="创建时间" width="200"></el-table-column>
          <el-table-column label="操作" width="130">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="small"
                @click="jump_order_modify(scope.row.virtualPayId)"
                v-if="scope.row.status=='充值失败'"
              >补发卡密</el-button>
              <el-button
                type="text"
                size="small"
                @click="jump_order_return(scope.row.extraOrderId)"
                v-if="scope.row.status=='充值失败'"
              >退款</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :currentPage="currentPage"
          :page="page"
          :total="total"
          :pageSize="pageSize"
          @change-current="currentChange"
          @change-size="sizeChange"
        ></pagination>
      </div>
    </div>
  </div>
</template>
<script>
import breadcrumb from "../../components/breadcrumb";
import pagination from "../../components/page";
import { mapActions } from "vuex";
export default {
  components: { breadcrumb, pagination },
  data() {
    return {
      currentPage: 1,
      pageSize: 10,
      page: 1,
      total: 0,
      options1: [],
      options2: [
        { value2: "", label: "全部" },
        { value2: "1", label: "待付款" },
        { value2: "2", label: "未填地址" },
        { value2: "3", label: "待发货" },
        { value2: "4", label: "待收货" },
        { value2: "5", label: "待评价" },
        { value2: "6", label: "已完成" },
        { value2: "7", label: "待分享" },
        { value2: "8", label: "待领取" },
        { value2: "9", label: "售后" },
        { value2: "10", label: "已关闭" }
      ],
      orderList: [],
      orderNo: "",
      userId: "",
      goodsName: "",
      positionId: "",
      beginTime: "",
      endTime: "",
      options3: [
        { value: "0", label: "充值中" },
        { value: "1", label: "充值成功" },
        { value: "9", label: "充值失败" },
        { value: "-1", label: "查询不到此订单" }
      ]
    };
  },
  created() {
    this.get_orderList();
    // 获取商品类型
    this.positions();
  },
  methods: {
    positions() {
      this.$axios.post("/web_goods_pos/list").then(res => {
        this.options1 = res.data.data;
        this.options1.unshift({ id: "", position: "全部" });
      });
    },
    sizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1;
      this.get_orderList();
    },
    currentChange(val) {
      this.currentPage = val;
      this.get_orderList();
    },
    jump_order_return(extraOrderId) {
      this.$axios
        .post("/web_order/virtualRefund?extraOrderId" + extraOrderId)
        .then(result => {
          if (result.data.status == 0) {
            if (result.data.data.status == 0) {
              this.get_orderList();
              return this.$message({
                type: "success",
                message: "操作成功"
              });
            } else {
              return this.$message({
                type: "warning",
                message: "操作失败"
              });
            }
          }
        });
    },
    jump_order_modify(virtualPayId) {
      this.$axios
        .post("/web_order/webReissue?virtualPayId=" + virtualPayId)
        .then(result => {
          if (result.data.status == 0) {
            if (result.data.data.retCode == 1) {
              this.get_orderList();
              return this.$message({
                type: "success",
                message: "操作成功"
              });
            } else {
              return this.$message({
                type: "warning",
                message: "操作失败"
              });
            }
          }
        });
    },
    get_orderList() {
      var data =
        "current=" +
        this.currentPage +
        "&size=" +
        this.pageSize +
        "&orderNo=" +
        this.orderNo +
        "&userId=" +
        this.userId +
        "&goodsName=" +
        this.goodsName +
        "&positionId=" +
        this.positionId +
        "&beginTime=" +
        this.beginTime +
        "&endTime=" +
        this.endTime;
      this.$axios.post("/web_order/list", data).then(result => {
        if (result.data.status == 0) {
          this.orderList = result.data.data.records;
          this.total = result.data.data.total;
          this.page = result.data.data.pages;
          //console.log(this.orderList, "111");

          // this.options3.forEach(item => {
          //   if (item.value == this.orderList.status) {
          //     this.orderList.status = item.label;
          //   }
          //   //console.log(item.value, "111", item.label);
          // });
          this.orderList.forEach(item => {
            switch (item.status) {
              case 0:
                item.status = "充值中";
                break;
              case 1:
                item.status = "充值成功";
                break;
              case 9:
                item.status = "充值失败";
                break;
              case -1:
                item.status = "查询不到此订单";
                break;

              default:
                break;
            }
          });
        }
      });
    },
    // 校验结束时间
    verfy_startTime() {
      if (this.startTime) {
        this.timeCompare(1);
      }
    },
    //   校验结束时间
    verfy_endtime() {
      if (this.endTime) {
        this.timeCompare(2);
      }
    },

    timeCompare(flag) {
      //  flag  用于标记是清楚开始时间，还是清楚结束时间
      if (
        new Date(this.startTime).getTime() >= new Date(this.endTime).getTime()
      ) {
        if (flag == 1) {
          this.startTime = "";
        } else {
          this.endTime = "";
        }
        return this.$message({
          type: "warning",
          message: "'拼团创建时间-开始'必须小于'拼团创建时间-结束'"
        });
      }
    }
  }
};
</script>

<style lang="less" >
.ordermanage-container {
  @import "../../style/table.less";
  @import "../../style/content.less";
  display: flex;
  flex-flow: column;
  position: relative;
  height: 100%;
  .el-table .cell {
    white-space: pre-line !important;
  }

  //更改行高
  .el-table__row td {
    height: 50px;
    padding: 0;
  }
  .content {
    .query {
      .start_time {
        display: flex;
        align-items: center;
      }
      .end_time {
        display: flex;
        align-items: center;
      }
      .btn {
        .el-button {
          width: 70px;
        }
      }
    }
  }
}
</style>

